<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        var reg1 = new RegExp("ab" , "i"); //reg1 = /ab/i;
        var text1 = "ca2bga3b";
        console.log(reg1.test(text1));
        console.log(reg1);

        var reg2 = /a[bde]c/;
        var text2= "ac";
        console.log(reg2.test(text2));

        text3 = "red,blue,green,,yellow.purple,111";
        console.log(text3.split(/[^,]+/));
        console.log(text3.search(/,/));
        console.log(text3.match(/[A-z]/g).join("")); //返回数组
        console.log(text3.replace(/,/ig, "."));
        console.log(text3.replace(/[A-z]/ig, "")); //替换后需要赋值

        var text4 = "aa";
        var reg4 = new RegExp(_reg4, "i");
        var _reg4 = "aaa";
        var reg5 = /a{3}/;
        var reg6 = /^a$/i;
/*         console.log(reg4.test(text4));
        console.log(reg5.test(text4));
        console.log(reg6.test(text4)); */

        //是否合法手机号
        var text5 = "141111e11111";
        var reg7 = /^1[3-9][0-9]{9}$/;
        console.log(reg7.test(text5));

        //用户名优化
        var text8 = "   ad  min   ";
        text8 = text8.replace(/^\s*|\s*$/g ,"")
        console.log(text8);

        //邮件正则 格式 任意字母数字下划线3-n .任意数字字母下划线 @ 任意字母数字 .2-5字母 .2-5字母
        var text8 = "123@qq.com.cn";
        var reg8 = /^\w{3,}(\.\w+)*@[A-Za-z0-9]+\.[A-Za-z]{2,5}(\.[A-Za-z]{2,5})*$/;
        console.log(reg8.test(text8));

    </script>
</body>
</html>